<template>
  <div class="app-container">
    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '维护',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center  :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="120px">
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>业务入账状态查询应答录入</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原系统流水号" prop="id">
                <el-input v-model="detailForm.id" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate">
                <el-date-picker
                  v-model="detailForm.workdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="来往标识" prop="drct">
                <el-select style="width: 100%" v-model="detailForm.drct" placeholder="来往标识" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.DRCTCODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="原报文标识号" prop="oriPkgId">
                <el-input v-model="detailForm.oriPkgId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原报文类型" prop="oriMsgType">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.oriMsgType === null || detailForm.oriMsgType === undefined
                      ? ''
                      : detailForm.oriMsgType + '-' + detailForm.oriMsgTypeDesc
                  "
                  placeholder="原报文类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <div v-if="this.detailForm.sysCode === 'HVPS'">
            <el-row type="flex">
              <el-col :span="12">
                <el-form-item label="原发起参与机构" prop="oriSender">
                  <el-input v-model="detailForm.oriSender" :disabled="true" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row type="flex">
              <el-col :span="12">
                <el-form-item label="原发起间接参与机构" prop="oriIndirectSender">
                  <el-input v-model="detailForm.oriIndirectSender" :disabled="true" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="原接收间接参与机构" prop="oriIndirectRecver">
                  <el-input v-model="detailForm.oriIndirectRecver" :disabled="true" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row type="flex">
              <el-col :span="12">
                <el-form-item label="原明细标识号" prop="oriDtlNo">
                  <el-input v-model="detailForm.oriDtlNo" :disabled="true" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="原业务类型编码" prop="oriBizType">
                  <el-select
                    style="width: 100%"
                    v-model="
                      detailForm.oriBizType === null || detailForm.oriBizType === undefined
                        ? ''
                        : detailForm.oriBizType + '-' + detailForm.oriBizTypeDesc
                    "
                    placeholder="原业务类型编码"
                    :disabled="true"
                  ></el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="待查询业务货币符号" prop="amountcurcd">
                <el-input v-model="detailForm.amountcurcd" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="待查询业务金额" prop="amount">
                <ht-amount-input
                  v-model="detailForm.amount"
                  placeholder="待查询业务金额"
                  :disable="true"
                ></ht-amount-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>业务入账状态查询应答录入</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="入账状态" prop="transStatus">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.transStatus"
                  placeholder="入账状态"
                  @change="transStatusChange"
                >
                  <el-option
                    v-for="dict in dictMap.TRANS_TYPE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="退汇原因" prop="reeChgInfo">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.reeChgInfo"
                  placeholder="退汇原因"
                  @change="transStatusChange"
                >
                  <el-option
                    v-for="dict in dictMap.REE_CHG_INFO"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="处理信息" prop="procInfo">
                <el-input type="textarea" v-model="detailForm.procInfo"  maxlength="105" show-word-limit />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submit" v-loading.fullscreen.lock="loading">提 交</el-button>
        <el-button type="primary" @click="refresh">重 置</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigQuery,
  ccmsBusinessAccountQueryRespondEntry,
  ccmsBusinessAccountQueryRespondEntryDetail,
} from "@/api/cnaps/ccms/321";
import { listPageMixin } from "@/libs/listPageMixin";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import HtAmountInput from "@/views/components/HtAmountInput";
export default {
  name: "CcmsBusinessAccountQuery",
  mixins: [listPageMixin],
  components: { HtAmountInput },
  data() {
    return {
      // 查询参数
      queryParams: {},
      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["DRCTCODE", "TRANS_TYPE", "REE_CHG_INFO"],
      // 列信息
      regConfig: apiUrlConfigQuery,
      tableBindColumns: [
        { prop: "id", label: "原系统流水号", width: 180 },
        { prop: "workdate", label: "工作日期", type: "date" },
        { prop: "drct", label: "报文320来往账标志", dictCode: "DRCTCODE", width: 180 },
        { prop: "oriPkgId", label: "原报文标识号", width: 180 },
        { prop: "oriSender", label: "原发起参与机构", width: 180 },
        {
          prop: "oriMsgType",
          label: "原报文类型",
          formatter(row, text, index) {
            return row["oriMsgType"] + "-" + row["oriMsgTypeDesc"];
          },
          width: 240,
        },
        {
          prop: "amount",
          label: "待查询业务金额",
          type: "price",
          width: 180,
        },
      ],
      loading: false,
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {
        amount: 0.0,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {
        transStatus: [{ required: true, message: "请选择入账状态", trigger: "blur" }],
        reeChgInfo: [{ required: false, message: "请选择退汇原因", trigger: "blur" }],
        procInfo: [{ required: false, message: "请输入处理信息", trigger: "blur" }],
      },
    };
  },
  mounted() {
    const formOptions = [];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "业务入账状态查询应答录入维护";
      ccmsBusinessAccountQueryRespondEntryDetail(row).then((response) => {
        this.resetForm("detailForm");
        this.detailForm = response.result;
        this.open = true;
      });
    },

    transStatusChange() {
      const transStatus = this.detailForm.transStatus;
      if (transStatus === "TA04" || transStatus === "TA05") {
        this.$set(this.rules.reeChgInfo[0], "required", true);
      } else {
        this.$set(this.rules.reeChgInfo[0], "required", false);
      }

      const reeChgInfo = this.detailForm.reeChgInfo;
      if (reeChgInfo === "RC07") {
        this.$set(this.rules.procInfo[0], "required", true);
      } else {
        this.$set(this.rules.procInfo[0], "required", false);
      }
    },

    //点击提交按钮
    submit: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          ccmsBusinessAccountQueryRespondEntry(this.detailForm)
            .then((response) => {
              this.msgSuccess("提交成功");
              this.loading = false;
              this.open = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },

    //点击重置按钮
    refresh() {
      this.resetForm("detailForm");
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
